<!--  Nguyen Huu Nhat -->
<?php
@session_start();
include '../Security/CheckAdmin.php';
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
textarea,option {
	width: 100%;
}
</style>
<script type="text/javascript">
//入力したデータの検査
function onlyLetter(t, e){
	c = e.keyCode;
if(!((c>=65 && c<=90) || (c>=97&&c<=122) || c==8))
	t.value = t.value.substring(0, t.value.length-1);
}
//メールアドレス
function checkMail() {
  var mail = document.forms[0].elements[5].value;
  var reg = new RegExp("\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
  x = document.getElementById('mailcheck');
  if(!reg.test(mail) || mail == "")
  { 
  //alert("Your email address isn't valid!");
  x.innerHTML='無効メールアドレス';
   return false;
  }
  else {
	  //x.innerHTML='valid mail';
	  x.innerHTML ='';   
	  return true;
  }
}
//パスワード
function checkPassWord(){
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var pass1 = document.forms[0].elements[1].value;
	var pass2 = document.forms[0].elements[2].value;

	x=document.getElementById('passwordcheck');
	//alert("Your email address isn't valid!");
	//Check bang nhau
	if(pass1 != pass2){
		//alert("Your email address isn't valid!");
		x.innerHTML='パスワードとパスワード確認が違う';
		return false;
	}
//	else
	//	x.innerHTML='bang nhau';

	// Check length
	if(pass1.length < minLength){
		x.innerHTML ='パスワードの長さは６より小さい';
		return false;
	}

	//Check khoang trang
	if(pass1.indexOf(invalid) >-1){
		x.innerHTML ='パスワードでが空欄を含む';
		return false;
	}

	//Check chu so
	re = /[0-9]/;
	if(!re.test(pass1)) {
		x.innerHTML ='パスワードでは数字がない';
		 return false; 
		 } 

	 //Check chu thuong
	 re = /[a-z]/;
	if(!re.test(pass1)) {
		x.innerHTML ='パスワードでは小文字がない';
		 return false; 
		 } 

	 //Check chu hoa
	 re = /[A-Z]/;
	if(!re.test(pass1)) {
		x.innerHTML ='パスワードでは大文字がない';
		 return false; 
		 } 
	x.innerHTML ='';
	return true;
}
//ネーム
function checkName(){
	var name = document.forms[0].elements[3].value;
	
	x=document.getElementById('nameCheck');
	if((name.length ==0) || (name == " ")){
		x.innerHTML='名前はない';
		return false;
	}
	x.innerHTML ='';
	return true;
}
//電話番号
function checkPhone(){
	var phone = document.forms[0].elements[4].value;
	
	x=document.getElementById('phoneCheck');
	if((phone.length ==0) || (phone == " ")){
		x.innerHTML='電話番号はない';
		return false;
	}
	x.innerHTML ='';
	return true;
} 
//アドレス
function checkAddress(){
	var address = document.forms[0].elements[6].value;

	x= document.getElementById('addressCheck');
	if((address.length == 0) || (address ==" ")){
		x.innerHTML = '住所がない';
		return false;
	}
	x.innerHTML ='';
	return true;
}

function validatorOnSubmit(){
	var result = true;

	if(!checkMail()) result = false;
	if(!checkPassWord()) result = false;
	if(!checkName()) result = false;
	if(!checkPhone()) result = false;
	if(!checkAddress()) result = false;
	
	return result;
}
</script>
</head>
<!--ユーザ作成の画面-->
<h1>ユーザ作成</h1>
<form action='CreateUserEx.php' method='get'
	onSubmit="return validatorOnSubmit()">
<table>
	<tr>
		<td>アカウント名</td>
		<td><input type='text' name='accountName'></td>
		<td id='accountCheck' 　style="color: #FF0000"></td>
	</tr>

	<tr>
		<td>パスワード</td>
		<td><input type='password' name='pass1'></td>
		<td id='passwordcheck' style="color: #FF0000"></td>
	</tr>

	<tr>
		<td>パスワード確認</td>
		<td><input type='password' name='pass2'></td>
		<td id='passwordcheck' style="color: #FF0000"></td>
	</tr>

	<tr>
		<td>名前</td>
		<td><input type='text' name='fullName'></td>
		<td id='nameCheck' style="color: #FF0000"></td>
	</tr>

	<tr>
		<td>電話番号</td>
		<td><input type='text' name='phone'></td>
		<td id='phoneCheck' style="color: #FF0000"></td>
	</tr>

	<tr>
		<td>メールアドレス</td>
		<td><input type='text' name='mail'></td>
		<td>
		<div id='mailcheck' style="color: #FF0000"></div>
		</td>
	</tr>

	<tr>
		<td>住所</td>
		<td><input type='text' name='address' size='50'></td>
		<td id='addressCheck' style="color: #FF0000"></td>
	</tr>
</table>
<input type=checkbox value=true name='isAdmin'>管理者<br></br>
<input type='submit' value='作成'
	style="height: 40px; width: 100px; margin-left: 140px; margin-top: 30px; font-size: 1.3em;">
</form>
</html>
